﻿using System;
using System.Drawing;

namespace Rimifier.Support
{
  public static class ExtensionMethods
  {
    public static Color ToColor(this uint argb)
    {
      return Color.FromArgb((byte) ((argb & -16777216) >> 0x18), (byte) ((argb & 0xff0000) >> 0x10), (byte) ((argb & 0xff00) >> 8), (byte) (argb & 0xff));
    }

    public static string ToHex(this Color color)
    {
      return String.Format("#{0}{1}{2}{3}", color.A.ToString("X").Length == 1 ? String.Format("0{0}", color.A.ToString("X")) : color.A.ToString("X"), color.R.ToString("X").Length == 1 ? String.Format("0{0}", color.R.ToString("X")) : color.R.ToString("X"), color.G.ToString("X").Length == 1 ? String.Format("0{0}", color.G.ToString("X")) : color.G.ToString("X"), color.B.ToString("X").Length == 1 ? String.Format("0{0}", color.B.ToString("X")) : color.B.ToString("X"));
    }

  }
}
